<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>密友绑定</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta name="format-detection" content="telephone=no" />
<link href="{$Think.config.RESOURCEURL}wx_assets/css/common.css{$Think.config.RESOURCE_VER}" rel="stylesheet" type="text/css">
<link href="{$Think.config.RESOURCEURL}wx_assets/quan/bind.css{$Think.config.RESOURCE_VER}" rel="stylesheet" type="text/css">
<script type="text/javascript" src="{$Think.config.RESOURCEURL}wx_assets/js/zepto.1.1.3.min.js{$Think.config.RESOURCE_VER}"></script>
<script type="text/javascript" src="{$Think.config.RESOURCEURL}wx_assets/js/zepto.alert.js{$Think.config.RESOURCE_VER}"></script>
<script src="{$Think.config.RESOURCEURL}wx_assets/js/util.js{$Think.config.RESOURCE_VER}" type="text/javascript"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script src="{$Think.config.RESOURCEURL}wx_assets/js/wx_share.js{$Think.config.RESOURCE_VER}" type="text/javascript"></script>
</head>
<body>
<div class="main">
    <!-- <div class="binding" id="bindBox">
        <input class="text_input" id="mobile" type="text" placeholder="请输入手机号" />
        <div class="otn">
            <div class="yzm">
                <input class="text_input" id="vCode" type="tel" placeholder="输入短信验证码" />
            </div>
            <a class="obtain" id="BtnGetCode">获取验证码</a>
        </div>
        <a id="BtnOk" class="buttond">确定 </a>
    </div> -->
</div>
<script>
    var baseUrl = '{$Think.config.SERVER_HOST}';
	var bind={
        init:function(){
            //this._initValidate();
            $.util.pageLoading.show("加载中...");
        },
        /**
         * [_saveBind 保存绑定]
         * @return {[type]} [description]
         */
        _saveBind:function(){
            $.req.get("call.json?customerId={$customerId}&module=quan&method=saveBind",{
                userName:"{$userName}",
                params:{
                    "mobile":$("#mobile").val(),
                    "code":$("#vCode").val()
                }
            },function(data){
                if(!data.code) {
                    var qId=data.qId;
                    $.util.showMsg("绑定成功!",function(){
                        if(!qId) {
                            location.href='{$Think.config.SERVER_HOST}call.html?customerId={$customerId}&userName={$userName}&module=quan&method=getQuan';
                        } else {
                            location.href='{$Think.config.SERVER_HOST}call.html?customerId={$customerId}&module=quan&method=index&params=%7B"qId"%3A"'+qId+'"%7D';
                        }  
                    });
                } else {
                    $.util.alert(data.msg);
                }
            });
        },
        /**
         * [_sendSmsCode 发送验证码]
         * @return {[type]} [description]
         */
        _sendSmsCode:function(){
            var me=this;
            $.req.get("call.json?customerId={$customerId}&module=quan&method=sendSmsCode",{
                userName:"{$userName}",
                params:{
                    "mobile":$("#mobile").val()
                }
            },function(data){
                if(data){
                    if(!data.code) {
                        me._DownTime();
                    } else {
                        $.util.showMsg("亲，密友圈会员都是定向邀请的，请联系你的邀请人或加QQ：3273695856申请。");
                    }
                }
            });
        },
        _DownTime:function(){
            $("#BtnGetCode").addClass("sended");
            var time=60;
            $("#BtnGetCode").text('已发送( '+time+' )');
            var timer=setInterval(function(){
                if(time > 1 ){
                     time--;
                    $("#BtnGetCode").text('已发送( '+time+' )');
                } else {
                    clearInterval(timer);
                    $("#BtnGetCode").removeClass("sended")
                                    .text("重新获取");
                }
            },1000)
        },
        _initValidate:function(){
            var me = this;
            var config = {};
            config = {
                "mobile": {
                    rule: {
                        required: {
                            message: "请输入11位手机号码！"
                        },
                        mobile: {
                            message: "请输入11位手机号码！"
                        }
                    },
                    pos: "bottom"
                }
            }
            var va = new Validate("bindBox", config);
            var va1=new Validate("bindBox",{
                "mobile": {
                    rule: {
                        required: {
                            message: "请输入11位手机号码！"
                        },
                        mobile: {
                            message: "请输入11位手机号码！"
                        }
                    },
                    pos: "bottom"
                },
                "vCode": {
                    focus:1,
                    rule: {
                        required: {
                            message: "请输入验证码！"
                        }
                    },
                    pos: "bottom"
                }
            });
            $("#BtnGetCode").click(function() {
                if(!$("#mobile").val()){
                    $("#vCodeTip").hide();
                }
                va.validate(function(result) {
                    if (result) {
                        if(!$("#BtnGetCode").hasClass("sended")) {
                            me._sendSmsCode();
                        }
                    }
                });
            });
            $("#BtnOk").click(function() {
                va1.validate(function(result) {
                    if (result) {
                        me._saveBind();
                    }
                });
            });
        }
    }
    bind.init();
    wx_share.init({
        "pkg":{
            "appId": '{$pkg.appId}',
            "timestamp": {$pkg.timestamp},
            "nonceStr": '{$pkg.nonceStr}',
            "signature": '{$pkg.signature}'
        },
        hide:1
    });
</script>
</body>
</html>